{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "\\begin{equation*} phi = \\phi ^{t}  \\boldsymbol{e}_{t} + \\phi ^{x}  \\boldsymbol{e}_{x} + \\phi ^{y}  \\boldsymbol{e}_{y} + \\phi ^{z}  \\boldsymbol{e}_{z} \\end{equation*}"
      ],
      "text/plain": [
       "phi__t*e_t + phi__x*e_x + phi__y*e_y + phi__z*e_z"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from galgebra.ga import Ga\n",
    "from sympy import symbols\n",
    "from galgebra.printer import Format\n",
    "\n",
    "Format()\n",
    "coords = (et,ex,ey,ez) = symbols('t,x,y,z',real=True)\n",
    "base=Ga('e*t|x|y|z',g=[1,-1,-1,-1],coords=symbols('t,x,y,z',real=True),wedge=False)\n",
    "\n",
    "potential=base.mv('phi','vector',f=True)\n",
    "potential"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "\\begin{equation*} \\left ( \\partial_{t} \\phi ^{t}  + \\partial_{x} \\phi ^{x}  + \\partial_{y} \\phi ^{y}  + \\partial_{z} \\phi ^{z} \\right )  + \\left ( \\partial_{x} \\phi ^{t}  + \\partial_{t} \\phi ^{x} \\right ) \\boldsymbol{e}_{tx} + \\left ( \\partial_{y} \\phi ^{t}  + \\partial_{t} \\phi ^{y} \\right ) \\boldsymbol{e}_{ty} + \\left ( \\partial_{z} \\phi ^{t}  + \\partial_{t} \\phi ^{z} \\right ) \\boldsymbol{e}_{tz} + \\left ( \\partial_{y} \\phi ^{x}  - \\partial_{x} \\phi ^{y} \\right ) \\boldsymbol{e}_{xy} + \\left ( \\partial_{z} \\phi ^{x}  - \\partial_{x} \\phi ^{z} \\right ) \\boldsymbol{e}_{xz} + \\left ( \\partial_{z} \\phi ^{y}  - \\partial_{y} \\phi ^{z} \\right ) \\boldsymbol{e}_{yz} \\end{equation*}"
      ],
      "text/plain": [
       "D{t}phi__t + D{x}phi__x + D{y}phi__y + D{z}phi__z + (D{x}phi__t + D{t}phi__x)*e_tx + (D{y}phi__t + D{t}phi__y)*e_ty + (D{z}phi__t + D{t}phi__z)*e_tz + (D{y}phi__x - D{x}phi__y)*e_xy + (D{z}phi__x - D{x}phi__z)*e_xz + (D{z}phi__y - D{y}phi__z)*e_yz"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "field=base.grad*potential\n",
    "field"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "\\begin{equation*} \\left ( \\partial^{2}_{t} \\phi ^{t}  - \\partial^{2}_{x} \\phi ^{t}  - \\partial^{2}_{y} \\phi ^{t}  - \\partial^{2}_{z} \\phi ^{t} \\right ) \\boldsymbol{e}_{t} + \\left ( \\partial^{2}_{t} \\phi ^{x}  - \\partial^{2}_{x} \\phi ^{x}  - \\partial^{2}_{y} \\phi ^{x}  - \\partial^{2}_{z} \\phi ^{x} \\right ) \\boldsymbol{e}_{x} + \\left ( \\partial^{2}_{t} \\phi ^{y}  - \\partial^{2}_{x} \\phi ^{y}  - \\partial^{2}_{y} \\phi ^{y}  - \\partial^{2}_{z} \\phi ^{y} \\right ) \\boldsymbol{e}_{y} + \\left ( \\partial^{2}_{t} \\phi ^{z}  - \\partial^{2}_{x} \\phi ^{z}  - \\partial^{2}_{y} \\phi ^{z}  - \\partial^{2}_{z} \\phi ^{z} \\right ) \\boldsymbol{e}_{z} \\end{equation*}"
      ],
      "text/plain": [
       "(D{t}^2phi__t - D{x}^2phi__t - D{y}^2phi__t - D{z}^2phi__t)*e_t + (D{t}^2phi__x - D{x}^2phi__x - D{y}^2phi__x - D{z}^2phi__x)*e_x + (D{t}^2phi__y - D{x}^2phi__y - D{y}^2phi__y - D{z}^2phi__y)*e_y + (D{t}^2phi__z - D{x}^2phi__z - D{y}^2phi__z - D{z}^2phi__z)*e_z"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "grad_field = base.grad*field\n",
    "grad_field"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "\\begin{equation*} \\left ( \\partial_{x} \\phi ^{t}  + \\partial_{t} \\phi ^{x} \\right ) \\boldsymbol{e}_{tx} \\end{equation*}"
      ],
      "text/plain": [
       "(D{x}phi__t + D{t}phi__x)*e_tx"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "part=field.proj([base.mv()[0]^base.mv()[1]])\n",
    "part"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "\\begin{equation*} \\left ( - \\partial^{2}_{x} \\phi ^{t}  - \\partial_{t}\\partial_{x} \\phi ^{x} \\right ) \\boldsymbol{e}_{t} + \\left ( \\partial^{2}_{t} \\phi ^{x}  + \\partial_{t}\\partial_{x} \\phi ^{t} \\right ) \\boldsymbol{e}_{x} + \\left ( - \\partial_{x}\\partial_{y} \\phi ^{t}  - \\partial_{t}\\partial_{y} \\phi ^{x} \\right ) \\boldsymbol{e}_{txy} + \\left ( - \\partial_{x}\\partial_{z} \\phi ^{t}  - \\partial_{t}\\partial_{z} \\phi ^{x} \\right ) \\boldsymbol{e}_{txz} \\end{equation*}"
      ],
      "text/plain": [
       "(-D{x}^2phi__t - D{t}{x}phi__x)*e_t + (D{t}^2phi__x + D{t}{x}phi__t)*e_x + (-D{x}{y}phi__t - D{t}{y}phi__x)*e_txy + (-D{x}{z}phi__t - D{t}{z}phi__x)*e_txz"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dpart = base.grad*part\n",
    "dpart"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
